import { requestModel, registerEntityType } from '../base'
import { registerEntityTable } from '../table'
import { initAircraftMapItems } from './map-item'
import type { Aircraft } from './types'
import AircraftFilterVue from './AircraftFilter.vue'

export * from './types'
export { aircraftMapItem } from './map-item'

function setupAircraftTable() {
  registerEntityTable<Aircraft>({
    type: 'Aircraft',
    columns: [
      {
        name: 'id',
        cell: (e) => e.id,
        width: 100
      },
      {
        name: '机型',
        cell: (e) => e.aircraftType || '',
        width: 100
      },
      {
        name: '航空公司',
        cell: (e) => e.airline || '',
        width: 100
      }
    ],
    filter: AircraftFilterVue
  })
}

export async function setupAircraft() {
  const data = (await requestModel('Aircraft')) as Aircraft[]
  registerEntityType<Aircraft>({
    type: 'Aircraft',
    typeName: '飞机',
    data
  })
  setupAircraftTable()
  initAircraftMapItems()
}
